﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.ComponentModel;
using Guedes_Library;

public partial class kit_refeitorio : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (Request.QueryString["p"] == null)
        {
            Response.Redirect("kit_refeitorio.aspx?p=1");
        }

        if (!Page.IsPostBack)
        {
            Repeater1.DataSource = GetProducts();
            Repeater1.DataBind();
        }

    }

    protected List<product> GetProducts()
    {
        List<product> data;
        using (guedesEntities _db = new guedesEntities())
        {
            data = (from p in _db.product
                    where p.ID_Cat == 4 // kit refeitório
                    orderby p.Name
                    select p).ToList();

            return data;
        }
    }

    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        ImageButton imgbtn = (ImageButton)e.Item.FindControl("imgProduct");
        imgbtn.ImageUrl = ResolveClientUrl("~/File/thumb/"+(e.Item.DataItem as product).Image);
        imgbtn.CommandArgument = (e.Item.DataItem as product).ID.ToString();

        Label title = (Label)e.Item.FindControl("lblTitle");
        title.Text = (e.Item.DataItem as product).Name;
    }

    protected void Image_OnClick(Object sender, CommandEventArgs e)
    {

        Session["idproduto"] = e.CommandArgument;
        Response.Redirect("produto_kit_refeitorio.aspx");

    }
}